<template>
  <div :class="className" style="width: 100%;height: 300px;" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'
import {getOwnerEcharts} from '@/api/village/owner'

export default {
  mixins: [resize],
  props: ['getOwnerTotal','className'],
  data() {
    return {
      chart: null,
      owner:[
        { value: 320, name: '未入住' },
        { value: 240, name: '已入住' },
      ]
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      getOwnerEcharts().then(res => {
        this.getOwnerTotal(res.data.total)

        this.chart = echarts.init(this.$el, 'macarons')
        this.chart.setOption({
          tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b} : {c} ({d}%)'
          },
          legend: {
            left: 'center',
            bottom: '10',
            data: ['已入住', '未入住']
          },
          series: [
            {
              name: '状态',
              type: 'pie',
              roseType: 'radius',
              radius: [15, 95],
              center: ['50%', '38%'],
              data: res.data.records,
              animationEasing: 'cubicInOut',
              animationDuration: 2600
            }
          ]
        })
      })
    }
  }
}
</script>
